import 'package:flutter_admin/models/odoo/udt_tb_docmentstock.dart';
import 'package:flutter_admin/utils/utils.dart';
import 'package:intl/intl.dart';

class UdtTbLendrecord {

  String? id;
  String? documentno;
  String? documentname;
  String? departmentId;
  String? departmentName;
  String? documenttypeId;
  String? documenttypeName;
  String? areaId;
  String? areaName;
  String? locationId;
  String? locationName;
  String? remark;
  String? lenddeptId;
  String? lenddeptName;
  String? lenddate;
  String? lendstartdate;
  String? lendenddate;
  String? lenduserId;
  String? lenduserName;
  String? returndeptId;
  String? returndeptName;
  String? returndate;
  String? returnuserId;
  String? returnuserName;
  String? createUid;
  String? createDate;
  String? writeUid;
  String? writeDate;
  String? status;

  UdtTbLendrecord({
    this.id,
    this.documentno,
    this.documentname,
    this.departmentId,
    this.departmentName,
    this.documenttypeId,
    this.documenttypeName,
    this.areaId,
    this.areaName,
    this.locationId,
    this.locationName,
    this.remark,
    this.lenddeptId,
    this.lenddeptName,
    this.lenddate,
    this.lendstartdate,
    this.lendenddate,
    this.lenduserId,
    this.lenduserName,
    this.returndeptId,
    this.returndeptName,
    this.returndate,
    this.returnuserId,
    this.returnuserName,
    this.createUid,
    this.createDate,
    this.writeUid,
    this.writeDate,
    this.status,
  });

  UdtTbLendrecord copyWith({
    String? id,
    String? documentno,
    String? documentname,
    String? departmentId,
    String? departmentName,
    String? documenttypeId,
    String? documenttypeName,
    String? areaId,
    String? areaName,
    String? locationId,
    String? locationName,
    String? remark,
    String? lenddeptId,
    String? lenddeptName,
    String? lenddate,
    String? lenduserId,
    String? lenduserName,
    String? returndeptId,
    String? returndeptName,
    String? returndate,
    String? returnuserId,
    String? returnuserName,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
  }) {
    return new UdtTbLendrecord(
      id: id ?? this.id,
      documentno: documentno ?? this.documentno,
      documentname: documentname ?? this.documentname,
      documenttypeId: documenttypeId ?? this.documenttypeId,
      documenttypeName: documenttypeName ?? this.documenttypeName,
      areaId: areaId ?? this.areaId,
      areaName: areaName ?? this.areaName,
      locationId: locationId ?? this.locationId,
      locationName: locationName ?? this.locationName,
      remark: remark ?? this.remark,
      lenddeptId: lenddeptId ?? this.lenddeptId,
      lenddeptName: lenddeptName ?? this.lenddeptName,
      lenddate: lenddate ?? this.lenddate,
      lenduserId: lenduserId ?? this.lenduserId,
      lenduserName: lenduserName ?? this.lenduserName,
      returndeptId: returndeptId ?? this.returndeptId,
      returndeptName: returndeptName ?? this.returndeptName,
      returndate: returndate ?? this.returndate,
      returnuserId: returnuserId ?? this.returnuserId,
      returnuserName: returnuserName ?? this.returnuserName,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
    );
  }

  @override
  String toString() {
    return '''UdtTbLendrecord{
      id: id,
      documentno: documentno,
      documentname: documentname,
      documenttypeId: documenttypeId,
      areaId: areaId,
      locationId: locationId,
      remark: remark,
      lenddeptId: lenddeptId,
      lenddate: lenddate,
      lenduserId: lenduserId,
      returndeptId: returndeptId,
      returndate: returndate,
      returnuserId: returnuserId,
      createUid: createUid,
      createDate: createDate,
      writeUid: writeUid,
      writeDate: writeDate,
    }''';
  }

  @override
  bool operator ==(Object other) => identical(this, other) || (
      other is UdtTbLendrecord &&
          runtimeType == other.runtimeType
          && id== other.id
          && documentno== other.documentno
          && documentname== other.documentname
          && documenttypeId== other.documenttypeId
          && areaId== other.areaId
          && locationId== other.locationId
          && remark== other.remark
          && lenddeptId== other.lenddeptId
          && lenddate== other.lenddate
          && lenduserId== other.lenduserId
          && returndeptId== other.returndeptId
          && returndate== other.returndate
          && returnuserId== other.returnuserId
          && createUid== other.createUid
          && createDate== other.createDate
          && writeUid== other.writeUid
          && writeDate== other.writeDate
   );


  factory UdtTbLendrecord.fromMap(Map<String, dynamic> map) {
    return new UdtTbLendrecord(
      id: map['id'].toString() as String?,
      documentno: map['documentno'].toString() as String?,
      documentname: map['documentname'].toString() as String?,
      departmentId: map['department_id'][0].toString() as String?,
      departmentName: map['department_id'][1].toString() as String?,
      documenttypeId: map['documenttype_id'][0].toString() as String?,
      documenttypeName: map['documenttype_id'][1].toString() as String?,
      areaId: map['area_id'][0].toString() as String?,
      areaName: map['area_id'][1].toString() as String?,
      locationId: map['location_id'][0].toString() as String?,
      locationName: map['location_id'][1].toString() as String?,
      remark: map['remark'].toString() as String?,
      lenddeptId: map['lenddept_id']!=false?map['lenddept_id'][0].toString() as String?:"",
      lenddeptName: map['lenddept_id']!=false?map['lenddept_id'][1].toString() as String?:"",
      lenddate: map['lenddate']!=false?Utils.getDate(date:map['lenddate'].toString()):'',
      lenduserId: map['lenduser_id']!=false?map['lenduser_id'][0].toString() as String?:"",
      lenduserName: map['lenduser_id']!=false?map['lenduser_id'][1].toString() as String?:"",
      returndeptId: map['returndept_id']!=false?map['returndept_id'][0].toString() as String?:'',
      returndeptName: map['returndept_id']!=false?map['returndept_id'][1].toString() as String?:'',
      returndate: map['returndate']!=false?Utils.getDate(date:map['returndate'].toString()):'',
      returnuserId: map['returnuser_id']!=false?map['returnuser_id'][0].toString() as String?:'',
      returnuserName: map['returnuser_id']!=false?map['returnuser_id'][1].toString() as String?:'',
      createUid: map['create_uid'].toString() as String?,
      createDate: map['create_date'].toString() as String?,
      writeUid: map['write_uid'].toString() as String?,
      writeDate: map['write_date'].toString() as String?,
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'documentno': this.documentno,
      'documentname': this.documentname,
      'departmentId': this.departmentId,
      'documenttypeId': this.documenttypeId,
      'areaId': this.areaId,
      'locationId': this.locationId,
      'remark': this.remark,
      'lenddeptId': this.lenddeptId,
      'lenddate': this.lenddate,
      'lenduserId': this.lenduserId,
      'returndeptId': this.returndeptId,
      'returndate': this.returndate,
      'returnuserId': this.returnuserId,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if(this.id!=null&&this.id!='')['id','=',this.id],
      if(this.documentno!=null&&this.documentno!='')['documentno','like',"%${this.documentno}%"],
      if(this.documentname!=null&&this.documentname!='')['documentname','like',"%${this.documentname}%"],
      if(this.departmentId!=null&&this.departmentId!='')['department_id','=',int.parse(this.departmentId!)],
      if(this.documenttypeId!=null&&this.documenttypeId!='')['documenttype_id','=',int.parse(this.documenttypeId!)],
      if(this.areaId!=null&&this.areaId!='')['area_id','=',int.parse(this.areaId!)],
      if(this.locationId!=null&&this.locationId!='')['location_id','=',int.parse(this.locationId!)],
      if(this.remark!=null&&this.remark!='')['remark','=',this.remark],
      if(this.lenddeptId!=null&&this.lenddeptId!='')['lenddept_id','=',int.parse(this.lenddeptId!)],
      if(this.lenddate!=null&&this.lenddate!='')['lenddate','=',this.lenddate],
      if(this.lendstartdate!=null&&this.lendstartdate!='')['lenddate','>=',this.lendstartdate! + " 00:00:00"],
      if(this.lendenddate!=null&&this.lendenddate!='')['lenddate','<=',this.lendenddate! + " 23:59:59"],
      if(this.lenduserId!=null&&this.lenduserId!='')['lenduser_id','=',int.parse(this.lenduserId!)],
      // if(this.lenduserName!=null&&this.lenduserName!='')['lenduser_id','=',int.parse(this.lenduserId!)],
      if(this.returndeptId!=null&&this.returndeptId!='')['returndept_id','=',int.parse(this.returndeptId!)],
      if(this.returndate!=null&&this.returndate!='')['returndate','=',this.returndate],
      if(this.returnuserId!=null&&this.returnuserId!='')['returnuser_id','=',int.parse(this.returnuserId!)],
      if(this.createUid!=null&&this.createUid!='')['create_uid','=',this.createUid],
      if(this.createDate!=null&&this.createDate!='')['create_date','=',this.createDate],
      if(this.writeUid!=null&&this.writeUid!='')['write_uid','=',this.writeUid],
      if(this.writeDate!=null&&this.writeDate!='')['write_date','=',this.writeDate],
      if(this.status!=null&&this.status!='')this.status=='0'?['returnuser_id','=',null]:['returnuser_id','!=',null],
    ] as List;
    if(list.length==0){
      list.add(['id','!=',null]);
    }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'documentno': this.documentno,
      'documentname': this.documentname,
      'department_id': this.departmentId,
      'documenttype_id': this.documenttypeId,
      'area_id': this.areaId,
      'location_id': this.locationId,
      'remark': this.remark,
      'lenddept_id': this.lenddeptId,
      'lenddate': this.lenddate,
      'lenduser_id': this.lenduserId,
      'returndept_id': this.returndeptId,
      'returndate': this.returndate,
      'returnuser_id': this.returnuserId,
      'create_uid': this.createUid,
      'create_date': this.createDate,
      'write_uid': this.writeUid,
      'write_date': this.writeDate,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}